import java.util.Stack;

public class Text4 {
//判断popV是否为pushV出栈的一种方式
    public static boolean isPopOrder(int[ ]pushV,int []popV){
        Stack <Integer> stack=new Stack<>();
        int j=0;
        for (int i = 0; i <pushV.length ; i++) {
            stack.push(pushV[i]);
            while ( j<popV.length&&!stack.isEmpty()&&stack.peek()==popV[j]){
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }
    //判断括号是否匹配
    public  static boolean isValid(String s){
        Stack<Character> stack=new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            if (ch=='('||ch=='['||ch=='{'){
                stack.push(ch);
            }
            else {
                if (stack.isEmpty()){
                    return false;
                }else {
                    char ch1=stack.peek();
                    if (ch1=='('&&ch==')'||ch1=='['&&ch==']'||ch1=='{'&&ch=='}'){
                        stack.pop();
                    }else {
                        return false;
                    }
                }
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        String arr="{{((()))}}";
        System.out.println(isValid(arr));
    }

    //逆波兰表达式求值
    public static int evalRPN(String[] tokens){
        Stack<Integer> stack=new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            if (isOperation(tokens[i])){
                Integer val=Integer.valueOf(tokens[i]);
                stack.push(val);
            }else {
                Integer val1=stack.pop();
                Integer val2=stack.pop();
                switch (tokens[i]){
                    case "+":
                        stack.push(val2+val1);
                        break;
                    case "-":
                        stack.push(val2-val1);
                        break;
                    case "*":
                        stack.push(val2*val1);
                        break;
                    case "/":
                        stack.push(val2/val1);
                        break;
                }
            }
        }
        return stack.pop();
    }
    public static boolean isOperation(String ret){
            if (ret=="+"||ret=="-"||ret=="*"||ret=="/"){
                return false;
            }
            else return true;
    }
    public static void main1(String[] args) {
        String[] arr=new String[]{"4","13","5","/","+"};
        int ret=evalRPN(arr);
        System.out.println(ret);
    }
}
